<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 新 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="../css/bootstrap.min.css">

<!-- 可选的Bootstrap主题文件（一般不用引入） -->
<link rel="../css/bootstrap-theme.min.css">
<script src="../js/jquery-1.9.1.js"></script>
<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="../js/bootstrap.min.js"></script>
<title>用户信息管理</title>
<link href="../themes/bootstrap/easyui.css" rel="stylesheet">
<link href="../themes/icon.css" rel="stylesheet">


<script src="../js/jquery.easyui.min.js"></script>
<script src="../js/easyui-lang-zh_CN.js"></script>
<script src="../js/user.js"></script>
</head>
<script type="text/javascript">
	$(function() {
		//默认对话框是关闭的
		$('#addUser').dialog('close');
		$('#updataUser').dialog('close');

		//配置增加表单
		$("#adUser").form({
			url : '${pageContext.request.contextPath}/addUser',
			success : function(data) {
				if (data == "1") {
					$('#addUser').dialog('close');
					$("#adUser").form('clear');
					$.messager.alert('我的消息', '增加成功', 'info', function() {
						$('#userMsg').datagrid('reload');
					});
				}
				else if(data=="2"){
					$.messager.alert('我的消息', '用户名重复', 'info', function() {
						$('#uact input').val(null);
					});
				}
			}
		})
		//配置修改表单
		$("#upUser").form({
			url : '${pageContext.request.contextPath}/updateUser',
			success : function(data) {
				if (data == "1") {
					$('#updataUser').dialog('close');
					$("#upUser").form('clear');
					$.messager.alert('我的消息', '更新成功', 'info', function() {
						$('#userMsg').datagrid('reload');
					});
				}
				else if(data=="2"){
					$.messager.alert('我的消息', '用户名重复', 'info', function() {
						$('#ract input').val(null);
					});
				}
				else {
					$.messager.alert('我的消息', '更新失败', 'info', function() {
						$('#userMsg').datagrid('reload');
					});
				}
			}
		})
		//配置搜索框
		$('#searchUser').searchbox({
			searcher : function(value, fname) {
				var fname = value;
				$('#userMsg').datagrid('reload', {
					searchname : fname
				});
			}
		});
		//配置数据表格
		$('#userMsg').datagrid({
			url : '${pageContext.request.contextPath}/findUser',
			columns : [ [ {
				field : 'checked',
				checkbox : true,				
				width : 100
			}, {
				field : 'uid',
				title : '用户编号',
				width : 100,
				hidden : true
			}, {
				field : 'uaccount',
				title : '用户账户',
				width : 100
			}, {
				field : 'upsw',
				title : '用户密码',
				width : 100,
				align : 'right'
			}, {
				field : 'ucard',
				title : '用户身份证',
				width : 150,
				align : 'right'
			}, {
				field : 'uname',
				title : '用户姓名',
				width : 50,
				align : 'right'
			},  {
				field : 'usex',
				title : '用户性别',
				width : 30,
				align : 'right'
			}, {
				field : 'uphone',
				title : '联系方式',
				width : 100,
				align : 'right'
			}, {
				field : 'uaddress',
				title : '配送地址',
				width : 280,
				
				align : 'right'
			}, {
				field : 'upicture',
				title : '用户头像',
				width : 105,
				align : 'right'
			}, ] ],
			pagination : true,
			toolbar : [ {
				iconCls : 'icon-add',
				text : '新增',
				handler : function() {
					$('#addUser').dialog('open');
				}
			}, '-', {
				iconCls : 'icon-remove',
				text : '删除',
				handler : function() {
				
					var u = Array();
					var temp = $("#userMsg").datagrid('getSelections');
					if(temp.length>0){
						$.each(temp,function(i,v){
							
							u[i]=v.uid;
						});
						$.ajax({
							traditional:true,
							url:'${pageContext.request.contextPath}/deleteUser',
							data:{'uid':u},
							datatype:String,
							success:function(data){
								if(data=='1'){
									$.messager.alert('我的消息', '删除成功', 'info', function() {
										$('#userMsg').datagrid('reload');
									});
								}
								if(data=='0'){
									$.messager.alert('我的消息', '删除失败', 'info', function() {
										$('#userMsg').datagrid('reload');
									});
								}
							}
						});
					}
					else{
						$.messager.confirm('提示', '请选择数据', function(r) {
							if (r) {
								$("#userMsg").datagrid('unselectAll');
							}
						})
					}

				}
			}, '-', {
				iconCls : 'icon-edit',
				text : '修改',
				handler : function() {
					
					var user = $("#userMsg").datagrid('getSelections');
					if (user.length != 1) {
						$.messager.confirm('提示', '请选择一条数据', function(r) {
							if (r) {
								$("#userMsg").datagrid('unselectAll');
							}
						})
					} else {
						$('#updataUser').dialog('open');
						var User = user[0];
						$('#upUser').form('load',User);

					}
				}
			} ],
			striped : true,
			rownumbers : true
		});
	})
	//配置更新表单提交事件
	function updataForm() {
		
		if($("#ract input").val()==""){
			alert("账户不能为空");
			return false;
		}
		if($("#rpsw input").val()==""){
			alert("密码不能为空");
			return false;
		}
		if($("#rcard input").val()==""){
			alert("身份证不能为空");
			return false;
		}
		if($("#rname input").val()==""){
			alert("姓名不能为空");
			return false;
		}
		if($("#rphone input").val()==""){
			alert("联系方式不能为空");
			return false;
		}
		$("#upUser").form('submit');
	}
	//配置增加表单
	function addForm() {
		if($("#uact input").val()==""){
			alert("账户不能为空");
			return false;
		}
		if($("#upsw input").val()==""){
			alert("密码不能为空");
			return false;
		}
		if($("#ucard input").val()==""){
			alert("身份证不能为空");
			return false;
		}
		if($("#uname input").val()==""){
			alert("姓名不能为空");
			return false;
		}
		if($("#uphone input").val()==""){
			alert("联系方式不能为空");
			return false;
		}
		$("#adUser").form('submit');
	}
	
</script>

<body style="background:url(../images/44.jpg);width: 100%; height: 100%">
<div style="text-align:right;">

</div>

	<input id="searchUser" class="easyui-searchbox" style="text-align:left;"
		data-options="prompt:'输入菜品名称查询信息',width:150">

	<form id="deleteUser" method="post">
		<table id="userMsg"></table>
	</form>
	
	
	
	<!-- 增加的对话框 -->
	<div id="addUser" class="easyui-dialog" title="增加用户"
		style="width: 400px; height: 450px;" data-options="modal:true">
		<form id="adUser" method="post">
<br>
			<div style="margin-bottom: 20px" id="uact" >
				<span>&nbsp;&nbsp;用户账户</span> 
				<input class="easyui-textbox" name="uaccount" style="width: 70%" id="uzh" value="" />
				<span style="color:red;font-size:20px">&nbsp;&nbsp;*</span>
			</div>
			
			<div style="margin-bottom: 20px" id="upsw">
				<span>&nbsp;&nbsp;用户密码</span> <input class="easyui-textbox" name="upsw" id="upsw"
					style="width: 70%"><span style="color:red;font-size:20px">&nbsp;&nbsp;*</span>
			</div>
			<div style="margin-bottom: 20px" id="ucard">
				<span>&nbsp;&nbsp;身份证号</span> <input class="easyui-textbox" name="ucard" id="ucard"
					style="width:70%; "><span style="color:red;font-size:20px">&nbsp;&nbsp;*</span>
			</div>
			<div style="margin-bottom: 20px" id="uname">
				<span>&nbsp;&nbsp;用户姓名</span> <input class="easyui-textbox" name="uname" id="uname"
					style="width: 70%;"><span style="color:red;font-size:20px">&nbsp;&nbsp;*</span>
			</div>
						
			<div class="form-group">
				<div class="form-group">
				<span>&nbsp;&nbsp;性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 别&nbsp;&nbsp;&nbsp;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
				<input type="radio" name="usex" id="usex" value="男" checked />&nbsp;&nbsp;男
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="radio"
			name="usex" id="usex" value="女" />&nbsp;&nbsp;女<span style="color:red;font-size:20px;float:right">*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
				</div>
			</div>
			
			<div style="margin-bottom: 20px;" id="uphone">
				<span>&nbsp;&nbsp;联系方式</span> <input class="easyui-textbox" name="uphone" id="uphone"
					style="width: 70%;" ><span style="color:red;font-size:20px">&nbsp;&nbsp;*</span>
			</div>
			<div style="margin-bottom: 20px;">
				<span>&nbsp;&nbsp;配送地址</span> <input class="easyui-textbox" name="uaddress" 
					style="width: 70%;height: 60px" ><span>(选填)</span>
			</div>
			<div style="margin-bottom: 20px;display:none">
				<span>&nbsp;&nbsp;用户头像</span> <input class="easyui-textbox" name="upicture"
					style="width:70%;" value="images/user.png">
			</div>
		</form>
		<div style="text-align: center; padding: 5px 0">
			<a href="javascript:void(0)" class="easyui-linkbutton"
				onclick="addForm()" style="width: 80px">提交</a>
		</div>

	</div>

	<!-- 修改的对话框 -->
	<div id="updataUser" class="easyui-dialog" title="更新食品信息"
		style="width: 400px; height: 450px;" data-options="modal:true">
		
		<form id="upUser" method="post">
               <div style="margin-bottom: 20px;display:none">
				<span>&nbsp;&nbsp;用户ID</span> <input class="easyui-textbox" name="uid" 
					style="width: 70%"><span style="color:red;font-size:20px">&nbsp;&nbsp;*</span>
			</div>
			<div style="margin-bottom: 20px" id="ract">
				<span>&nbsp;&nbsp;用户账户</span> <input class="easyui-textbox" name="uaccount" id="uaccount"
					style="width: 70%"><span style="color:red;font-size:20px">&nbsp;&nbsp;*</span>
			</div>
			<div style="margin-bottom: 20px" id="rpsw">
				<span>&nbsp;&nbsp;用户密码</span> <input class="easyui-textbox" name="upsw" id="upsw"
					style="width: 70%"><span style="color:red;font-size:20px">&nbsp;&nbsp;*</span>
			</div>
			<div style="margin-bottom: 20px" id="rcard">
				<span>&nbsp;&nbsp;身份证号</span> <input class="easyui-textbox" name="ucard" id="ucard"
					style="width: 70%;"><span style="color:red;font-size:20px">&nbsp;&nbsp;*</span>
			</div>
			<div style="margin-bottom: 20px" id="rname">
				<span>&nbsp;&nbsp;用户姓名</span> <input class="easyui-textbox" name="uname" id="uname"
					style="width: 70%;"><span style="color:red;font-size:20px">&nbsp;&nbsp;*</span>
			</div>
						
			<div class="form-group">
				<div class="form-group">
				<span>&nbsp;&nbsp;性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 别</span>
				<input type="radio" name="usex" id="usex" value="男" checked />男
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="radio"
			name="usex" id="usex" value="女" />女
				</div>
			</div>
			
			<div style="margin-bottom: 20px;" id="rphone">
				<span>&nbsp;&nbsp;联系方式</span> <input class="easyui-textbox" name="uphone" id="uphone"
					style="width: 70%;" ><span style="color:red;font-size:20px">&nbsp;&nbsp;*</span>
			</div>
			<div style="margin-bottom: 20px;">
				<span>&nbsp;&nbsp;配送地址</span> <input class="easyui-textbox" name="uaddress" 
					style="width: 70%; height: 60px" ><span>(选填)</span>
			</div>
			<div style="margin-bottom: 20px;display:none">
				<span>&nbsp;&nbsp;用户头像</span> <input class="easyui-textbox" name="upicture"
					style="width: 70%;" value="images/user.png">
			</div>
		</form>
		<div style="text-align: center; padding: 5px 0">
			<a href="javascript:void(0)" class="easyui-linkbutton"
				onclick="updataForm()" style="width: 80px">提交</a>
		</div>
	</div>
</body>
</html>